home *** CD-ROM | disk | FTP | other *** search
/ PC World Interactive 7 / PC World Interactive 7.iso / program / vbkontrol.exe / VBSTAK.ZIP / VBSTAK / VBMAIL / SENDMAIL.FRM (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-07-21  |  11.0 KB  |  364 lines

  1. VERSION 2.00
  2. Begin Form SendMailForm 
  3.    BorderStyle     =   3  'Fixed Double
  4.    Caption         =   "Mail"
  5.    ClientHeight    =   4605
  6.    ClientLeft      =   660
  7.    ClientTop       =   1950
  8.    ClientWidth     =   7395
  9.    Height          =   5010
  10.    Icon            =   0
  11.    Left            =   600
  12.    LinkTopic       =   "Form1"
  13.    MaxButton       =   0   'False
  14.    MDIChild        =   -1  'True
  15.    MinButton       =   0   'False
  16.    ScaleHeight     =   4605
  17.    ScaleWidth      =   7395
  18.    Top             =   1605
  19.    Width           =   7515
  20.    Begin SSFrame Frame3D1 
  21.       Height          =   4605
  22.       Left            =   30
  23.       TabIndex        =   0
  24.       Top             =   30
  25.       Width           =   7365
  26.       Begin VBSTAK MailStak 
  27.          Debug           =   0   'False
  28.          Host            =   "haddock2"
  29.          HostAddress     =   ""
  30.          InputLen        =   0
  31.          Left            =   5550
  32.          LocalAddress    =   ""
  33.          LocalPort       =   0
  34.          Options         =   0
  35.          Protocol        =   0
  36.          ProtocolName    =   "tcp"
  37.          RemotePort      =   0
  38.          ServiceName     =   "smtp"
  39.          Top             =   270
  40.       End
  41.       Begin SSCheck TestModeCheck 
  42.          Caption         =   "Test Mode"
  43.          Height          =   315
  44.          Left            =   4350
  45.          TabIndex        =   6
  46.          Top             =   420
  47.          Width           =   1545
  48.       End
  49.       Begin SSPanel Panel3D1 
  50.          BevelInner      =   1  'Inset
  51.          Height          =   405
  52.          Index           =   1
  53.          Left            =   780
  54.          TabIndex        =   15
  55.          Top             =   120
  56.          Width           =   3015
  57.          Begin TextBox MyAddressBox 
  58.             BorderStyle     =   0  'None
  59.             Height          =   225
  60.             Left            =   90
  61.             TabIndex        =   1
  62.             Top             =   90
  63.             Width           =   2835
  64.          End
  65.       End
  66.       Begin Timer LinkTimer 
  67.          Enabled         =   0   'False
  68.          Interval        =   10000
  69.          Left            =   3840
  70.          Top             =   210
  71.       End
  72.       Begin SSPanel StatusBox 
  73.          BevelInner      =   1  'Inset
  74.          Height          =   375
  75.          Left            =   780
  76.          TabIndex        =   9
  77.          Top             =   1020
  78.          Width           =   5445
  79.       End
  80.       Begin SSPanel Panel3D2 
  81.          BevelInner      =   1  'Inset
  82.          Height          =   2865
  83.          Left            =   60
  84.          TabIndex        =   8
  85.          Top             =   1680
  86.          Width           =   7245
  87.          Begin TextBox MessageBox 
  88.             Height          =   2715
  89.             Left            =   60
  90.             MultiLine       =   -1  'True
  91.             ScrollBars      =   2  'Vertical
  92.             TabIndex        =   3
  93.             Top             =   60
  94.             Width           =   7125
  95.          End
  96.       End
  97.       Begin CommandButton CloseButton 
  98.          Caption         =   "Close"
  99.          Height          =   315
  100.          Left            =   6270
  101.          TabIndex        =   4
  102.          Top             =   150
  103.          Width           =   1035
  104.       End
  105.       Begin CommandButton SendButton 
  106.          Caption         =   "Send"
  107.          Enabled         =   0   'False
  108.          Height          =   315
  109.          Left            =   6270
  110.          TabIndex        =   5
  111.          Top             =   450
  112.          Width           =   1035
  113.       End
  114.       Begin SSPanel Panel3D1 
  115.          BevelInner      =   1  'Inset
  116.          Height          =   405
  117.          Index           =   0
  118.          Left            =   780
  119.          TabIndex        =   7
  120.          Top             =   570
  121.          Width           =   3015
  122.          Begin TextBox AddressBox 
  123.             BorderStyle     =   0  'None
  124.             Height          =   225
  125.             Left            =   90
  126.             TabIndex        =   2
  127.             Top             =   90
  128.             Width           =   2835
  129.          End
  130.       End
  131.       Begin Label Label6 
  132.          BackColor       =   &H00C0C0C0&
  133.          Caption         =   "Message:"
  134.          Height          =   195
  135.          Left            =   90
  136.          TabIndex        =   10
  137.          Top             =   1470
  138.          Width           =   825
  139.       End
  140.       Begin Label Label5 
  141.          BackColor       =   &H00C0C0C0&
  142.          Caption         =   "Status:"
  143.          Height          =   255
  144.          Left            =   60
  145.          TabIndex        =   11
  146.          Top             =   1080
  147.          Width           =   735
  148.       End
  149.       Begin Label Label2 
  150.          BackColor       =   &H00C0C0C0&
  151.          Caption         =   "From:"
  152.          Height          =   315
  153.          Left            =   60
  154.          TabIndex        =   13
  155.          Top             =   150
  156.          Width           =   705
  157.       End
  158.       Begin Label Label1 
  159.          BackColor       =   &H00C0C0C0&
  160.          Caption         =   "To:"
  161.          Height          =   285
  162.          Left            =   150
  163.          TabIndex        =   16
  164.          Top             =   630
  165.          Width           =   585
  166.       End
  167.       Begin Label Label4 
  168.          BackColor       =   &H00C0C0C0&
  169.          Caption         =   "Link Timer"
  170.          Height          =   255
  171.          Left            =   4320
  172.          TabIndex        =   14
  173.          Top             =   180
  174.          Visible         =   0   'False
  175.          Width           =   1425
  176.       End
  177.    End
  178.    Begin Label Label3 
  179.       Caption         =   "Label3"
  180.       Height          =   30
  181.       Left            =   7440
  182.       TabIndex        =   12
  183.       Top             =   4650
  184.       Width           =   135
  185.    End
  186. Dim HostResponded As Integer
  187. Dim ServiceResponded As Integer
  188. Dim ProtocolResponded As Integer
  189. Dim LinkTime As Integer
  190. Sub CloseButton_Click ()
  191. ' Close the socket and release VBX
  192.   Unload Me
  193. End Sub
  194. Sub Form_Load ()
  195.   MailStak.Host = GetIniField("Host", "HostName", "vbmail.ini")
  196.   MailStak.ServiceName = GetIniField("Host", "SendService", "vbmail.ini")
  197. End Sub
  198. Sub LinkTimer_Timer ()
  199. ' Error on timeout
  200.   LinkTime = LinkTime - 1
  201.   If LinkTime = 0 Then
  202.     result = MsgBox("Link timeout", MB_ICONSTOP + MB_OK)
  203.     LinkTimer.Enabled = False
  204.   End If
  205. End Sub
  206. Sub MailStak_Message (message As Integer)
  207. ' Receive socket messages
  208.   Dim responseString As String
  209.   Select Case message
  210.   Case STAK_EVENT_HOST
  211.     HostResponded = True
  212.     processRequest ("Host")
  213.   Case STAK_EVENT_SERVICE
  214.     ServiceResponded = True
  215.     Call processRequest("Service")
  216.   Case STAK_EVENT_PROTOCOL
  217.     ProtocolResponded = True
  218.     Call processRequest("Protocol")
  219.   Case FD_READ
  220.     responseString = MailStak.Input
  221.     Call processMail(responseString)
  222.   Case FD_CONNECT
  223.   ' Connected to server
  224.     If MailStak.Error = 0 Then
  225.       Connected = True
  226.       closeButton.Enabled = False
  227.       StatusBox.Caption = "Connected to " & MailStak.Host
  228.     Else
  229.       StatusBox.Caption = "Cannot connect to host " & HostName
  230.     End If
  231.   Case FD_CLOSE
  232.   ' Remote Disconect
  233.     Connected = False
  234.     MailStak.Action = STAK_ACTION_CLOSE
  235.     closeButton.Enabled = True
  236.   End Select
  237. End Sub
  238. Sub MessageBox_Change ()
  239.   SendButton.Enabled = MyAddressBox.DataChanged And AddressBox.DataChanged
  240. End Sub
  241. Sub MyAddressBox_LostFocus ()
  242. ' Set my Address
  243.     MyAddress = MyAddressBox.Text
  244. End Sub
  245. Sub processMail (responseString As String)
  246. ' Process the mail response and update based on state
  247.   On Error GoTo ProcessMailError
  248.   LinkTimer.Enabled = False
  249.   If MailState <> SMTP_END Then
  250.     StatusBox.Caption = responseString
  251.   End If
  252.   ' If test node display and step
  253.   If TestMode Then
  254.     result = MsgBox("Mail State: " & Str(MailState), MB_OK)
  255.   End If
  256.   ' State machine for mail States
  257.   Select Case MailState
  258.   Case SMTP_IDLE
  259.     Exit Sub
  260.   Case SMTP_LOCATE_SERVICE
  261.     MailState = SMTP_LOCATING_SERVICE
  262.     Call StartTimer(STAK_WAIT_INTERVAL)
  263.     MailStak.Action = STAK_ACTION_GET_SERVICE
  264.   Case SMTP_LOCATING_SERVICE
  265.     'MailStak.ProtocolName = MailStak.ProtocolName & Chr(0)
  266.     MailState = SMTP_LOCATING_PROTOCOL
  267.     Call StartTimer(STAK_WAIT_INTERVAL)
  268.     MailStak.Action = STAK_ACTION_GET_PROTOCOL
  269.   Case SMTP_LOCATING_PROTOCOL
  270.     StatusBox.Caption = "Locating Host"
  271.     MailState = SMTP_LOCATING_HOST
  272.     MailStak.Action = STAK_ACTION_GET_HOST
  273.     StartTimer (STAK_SERVICE_INTERVAL)
  274.   Case SMTP_LOCATING_HOST
  275.       closeButton.Enabled = False
  276.       MailState = SMTP_CONNECT
  277.       StartTimer (STAK_WAIT_INTERVAL)
  278.       MailStak.Action = STAK_ACTION_OPEN
  279.   Case SMTP_CONNECT
  280.     If InStr(1, responseString, "220 ") <> 0 Then
  281.       MailState = SMTP_HELO
  282.       Call SendData("HELO " & MyAddress & Chr(10))
  283.     Else
  284.       'Error SMTP_ERROR
  285.     End If
  286.   Case SMTP_HELO
  287.     If InStr(1, responseString, "250 ") <> 0 Then
  288.       MailState = SMTP_MAIL_FROM
  289.       Call SendData("mail from:<" & MyAddress & ">" & Chr(10))
  290.     Else
  291.       ' Error SMTP_ERROR
  292.     End If
  293.   Case SMTP_MAIL_FROM
  294.     If InStr(1, responseString, "250 ") > 0 Then
  295.       MailState = SMTP_RCPT_TO
  296.       Call SendData("RCPT TO:<" & AddressBox.Text & ">" & Chr(10))
  297.     Else
  298.       Error SMTP_ERROR
  299.     End If
  300.   Case SMTP_RCPT_TO
  301.     If InStr(1, responseString, "250 ") Then
  302.       MailState = SMTP_DATA
  303.       Call SendData("DATA" & Chr(10))
  304.     Else
  305.       Error SMTP_ERROR
  306.     End If
  307.   Case SMTP_DATA
  308.     If InStr(1, responseString, "354 ") Then
  309.       MailState = SMTP_CLOSE
  310.       Call SendData(MessageBox.Text & Chr(10) & "." & Chr(10))
  311.     Else
  312.       Error SMTP_ERROR
  313.     End If
  314.   Case SMTP_CLOSE
  315.     If InStr(1, responseString, "250 ") Then
  316.       MailState = SMTP_END
  317.       Call SendData("QUIT" & Chr(10))
  318.     Else
  319.       Error SMTP_ERROR
  320.     End If
  321.   Case SMTP_END
  322.     Exit Sub
  323.   End Select
  324. ProcessMailExit:
  325.   Exit Sub
  326. ProcessMailError:
  327.   If Err = SMTP_ERROR Then
  328.     MailState = SMTP_IDLE
  329.     Resume ProcessMailExit
  330.   Else
  331.     result = MsgBox(" Error " & Error, MB_ICONSTOP + MB_OK)
  332.     Resume ProcessMailExit
  333.   End If
  334. End Sub
  335. Sub processRequest (requestType As String)
  336. ' Process the response to a host,service or protocol request
  337.     If MailStak.Error <> NO_ERROR Then
  338.       MailState = SMTP_IDLE
  339.       StatusBox.Caption = requestType & " Error " & Str(MailStak.Error)
  340.     Else
  341.       Call processMail("")
  342.     End If
  343. End Sub
  344. Sub SendButton_Click ()
  345. ' Query smail and wait for responses
  346.   MailState = SMTP_LOCATE_SERVICE
  347.   processMail ("")
  348. End Sub
  349. Sub SendData (dataBuffer As String)
  350. ' Send the buffer to the socket
  351.   StartTimer (STAK_WAIT_INTERVAL)
  352.   MailStak.Output = dataBuffer '& Chr(0)
  353.   MailStak.Action = STAK_ACTION_SEND
  354. End Sub
  355. Sub StartTimer (Interval As Integer)
  356.     LinkTime = Interval
  357.     LinkTimer.Interval = 1000
  358.     LinkTimer.Enabled = True
  359. End Sub
  360. Sub TestModeCheck_Click (Value As Integer)
  361.   ' Set the test mode
  362.   TestMode = TestModeCheck.Value
  363. End Sub
  364.